package com.bilin.coin.list;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.bilin.coin.R;
import com.bilin.coin.bean.DepthBean;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.utils.DensityUtils;
import com.bilin.coin.utils.SpacesItemDecoration;
import com.bilin.coin.widget.AbsPullToRefreshRecycleView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class DepthList extends AbsPullToRefreshRecycleView<DepthBean> {


    int type; //0委拍报价（荷式专场） 1 竞买报价（英式专场）

    public DepthList(BaseAppCompatActivity activity, RecyclerView recyclerView, int type) {
        super(activity,recyclerView, false,false,false, true);
        this.type = type;
    }

    @Override
    public int fillPageSize() {
        return 15;
    }

    @Override
    public boolean isPost() {
        return true;
    }

    @Override
    public List parseListDataAndFillTotal(String dataJson) {
        return null;
    }

    @Override
    public Map<String, String> fillParams() {
        HashMap params = new HashMap();
        return params;
    }

    @Override
    protected RecyclerView.LayoutManager fillLayoutManger() {
        LinearLayoutManager manager = new LinearLayoutManager(activity);
        manager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.addItemDecoration(new SpacesItemDecoration(1, DensityUtils.dp2px(activity, 0), 0x1999));
        return manager;
    }

    @Override
    public String fillUrl() {
        return "/api/app/data/depth";
    }

    @Override
    protected void convertItem(BaseViewHolder helper, DepthBean item) {

        helper.setText(R.id.tv_name, item.getArea()+"");
        helper.setText(R.id.tv_buy, item.getBuy()+"");
        helper.setText(R.id.tv_sell, item.getSell()+"");

        if (type == 0) {
            helper.setTextColor(R.id.tv_name, activity.getResources().getColor(R.color.green_common));
            helper.setTextColor(R.id.tv_buy, activity.getResources().getColor(R.color.green_common));
            helper.setTextColor(R.id.tv_sell, activity.getResources().getColor(R.color.green_common));
        } else {
            helper.setTextColor(R.id.tv_name, activity.getResources().getColor(R.color.red_common));
            helper.setTextColor(R.id.tv_buy, activity.getResources().getColor(R.color.red_common));
            helper.setTextColor(R.id.tv_sell, activity.getResources().getColor(R.color.red_common));
        }
    }

    @Override
    protected int fillAnimationType() {
        return BaseQuickAdapter.ALPHAIN;
    }

    @Override
    protected int fillItemLayout() {
        return R.layout.item_depth;
    }

    public void refreshMy(List<DepthBean> list) {
        adapter.setNewData(list);
    }
}
